package com.dimples.controller.view;

import com.dimples.common.constant.StrPool;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import java.util.Map;

import cn.hutool.core.util.StrUtil;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2021/6/24
 */
public abstract class BaseWebController {

    /**
     * 系统业务基础路径
     */
    public final static String API_SYSTEM_PREFIX = "system/";


    public static final String WEB_PRE = "dimples/";

    /**
     * 前端基础路径
     */
    public final static String WEB_SYSTEM_PREFIX = WEB_PRE +"system/";

    /**
     * 前端基础路径
     */
    public final static String WEB_MENU_PREFIX = WEB_PRE +"menu/";

    /**
     * 前端基础路径
     */
    public final static String WEB_ROLE_PREFIX = WEB_PRE +"role/";

    /**
     * 前端基础路径
     */
    public final static String WEB_USER_PREFIX = WEB_PRE +"user/";

    /**
     * 页面跳转
     */
    public ModelAndView toPage(String path) {
        path = StrUtil.startWith(path, StrPool.SLASH) ? StrUtil.removePrefix(path, StrPool.SLASH) : path;
        return new ModelAndView(path);
    }

    /**
     * 页面跳转,带参数
     */
    public ModelAndView toPage(String path, Map<String, Object> params) {
        ModelAndView view = new ModelAndView(path);
        view.addAllObjects(params);
        return view;
    }

    /**
     * 页面重定向
     */
    public ModelAndView redirect(String path) {
        return new ModelAndView(new RedirectView(path));
    }

    /**
     * 页面重定向, 带参数
     */
    public ModelAndView redirect(String path, Map<String, Object> params) {
        return new ModelAndView(new RedirectView(path), params);
    }

}
